<?php
/*
	提现
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
global $_RQ;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
cfc('core')->checklogin();
if($_RQ['op']=='get'){
	if($_SESSION['onemerchid']){
		$basic=model('jy_merch/member')->getdetail($_SESSION['onemerchid'],$_SESSION['uid']);
		$basic2=model('core/member')->detail($_SESSION['uid'],array('avatar','nickname'));
		$basic=array_merge($basic2,$basic);
	}else{
		$basic=model('core/member')->basic($_SESSION['uid']);
	}
	$item=pdo_get('jy_mjicai_team',array('merchid'=>$_SESSION['onemerchid'],'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$mymember=pdo_get('jy_mjicai_member',array('merchid'=>$_SESSION['onemerchid'],'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$item['level']=pdo_get('jy_mjicai_teamlevel',array('id'=>$item['level_id'],'uniacid'=>$_SESSION['uniacid']));
	$member=array_merge($basic,$item);
	$return['member']=$member;
	$return['mymember']=$mymember;
	$return['params']['type']=$_RQ['type']?:2;
	set_html('title','我的团队');
	exi($return);
}
if($_RQ['op']=='getlist'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'type'=>array(0,1,7,8,9,10,11));
    $orderby='createtime desc';
	$total='';
	$return['list']=pdo_getslice('jy_mjicai_feelog',$params,array($pindex,$psize),$total,$fields,'',$orderby);	
	foreach($return['list'] as &$v){
			$teampaixu=pdo_getcolumn('jy_mjicai_cang',array('id'=>$v['cangid'],'uniacid'=>$_SESSION['uniacid']),'paixu');
			$yaopaixu=pdo_getcolumn('jy_mjicai_yao',array('id'=>$v['cangid'],'uniacid'=>$_SESSION['uniacid']),'paixu');
			$v['createtime']=date('Y-m-d H:m:s',$v['createtime']);
			$v['statustitle']=$this->canlog_status[$v['status']];
			$v['typetitle']=$this->feelog_type[$v['type']];
			$v['db_title']=$this->db_title;
			$v['title']='第'.$teampaixu.'仓第'.$yaopaixu.''.$this->y_title;
	}
	exi($return);
}
if($_RQ['op']=='congzhi'){
	$post=get_postdata();
	if($post['isbaofee']){
		$member=pdo_get('jy_mjicai_member',array('merchid'=>$_SESSION['onemerchid'],'mid'=>$_SESSION['uid']));
	}else{
		$member=pdo_get('core_members',array('id'=>$_SESSION['uid']));
	}
	if(!$post['fee']){
		exi('请输入转账'.$this->db_title.'！','erroe');
	}
	if(!$post['mobile']){
		exi('请输入收款人账户/手机号！','erroe');
	}
	if($post['isbaofee']){
		if($member['baofee']<$post['fee']){
			exi('转账额度不能大于，当前剩余'.$this->db_title.'！','erroe');
		}
	}else{
		if($member['credit1']<$post['fee']){
			exi('转账额度不能大于，当前积分额度！','erroe');
		}
	}
	$tomember=pdo_get('core_members',array('username'=>$post['mobile']));
	$tomid=$tomember['id'];
	if(!$tomid){
		$tomember=pdo_get('core_members',array('mobile'=>$post['mobile']));
		$tomid=$tomember['onemid']?:$tomember['id'];
	}
	if(!$tomid){
		exi('没找到收款人，转账失败！','erroe');
	}
	if($post['isbaofee']){
		pdo_update('jy_mjicai_member',array('baofee -='=>$post['fee']),array('merchid'=>$_SESSION['onemerchid'],'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
		pdo_update('jy_mjicai_member',array('baofee +='=>$post['fee']),array('merchid'=>$_SESSION['onemerchid'],'mid'=>$tomid,'uniacid'=>$_SESSION['uniacid']));
		$feelog=array(
						'uniacid'=>$_SESSION['uniacid'],
						'mid'=>$_SESSION['uid'],
						'fee'=>$post['fee'],
						'remark'=>'转账给:'.$post['mobile'],
		);
		$this->model('model')->add_feelog($feelog,10);
		$feelog['mid']=$tomid;
		$this->model('model')->add_feelog($feelog,11);
	}else{
		model('core/member')->cut_credit1($_SESSION['uid'],$post['fee'],'转账给:'.$post['mobile']);
		model('core/member')->add_credit1($tomid,$post['fee'],$member['username'].'的转账');
	}
	exi('转账成功！');
}